
#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"

class OneLoop {
public:
    int get_index(char a){
        if(a>='0'&&a<='9'){
            return a-'0'+1;
        }
        switch (a) {
            case 'A':
                return 14;
            case 'K':
                return 13;
            case 'Q':
                return 12;
            case 'J':
                return 11;

        }
    }
    void run(
           std::vector<char> & vec
    ) {
        int cnt=0;
        std::vector<char> hand(vec.size());
        for(auto c:vec){
            int ins=get_index(c);
            if(ins>cnt){
                hand[cnt]=c;
            }else{
                //插入点后面的需要后弋
                // 假设cnt为4 插入到3 对应下标为2 0 1 2 3
                // i=3 i>2 0 1 2 _ 3
                for(int i=cnt-1;i>ins-1;i--){
                    hand[i+1]=hand[i];
                }
                hand[ins]=c;
            }
            cnt++;
        }
        for(auto c:hand){
            if(c=='9'){
                printf("10 ");
            }
            else if(c>='0'&&c<='8'){
                printf("%c ",c+1);
            }else{
                printf("%c ",c);
            }
        }
        printf("\n");
        ;
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int a, b, c, d, e;
        std::string s1, s2;
        std::vector<char> vec;
        int cnt=0;
        while(cnt<52){
            int aa;std::cin>>aa;
            if(std::cin.fail()){
                std::cin.clear();
                char cc=std::cin.get();
                if(cc==EOF){
                    printf("-1\n");
                    return;
                }
                if(cc!=' '&&cc!='\n'){
                    vec.push_back(cc);
                    cnt++;
                }
            }else{
                char cc=aa-1+'0';
                vec.push_back(cc);
                cnt++;
            }

        }
        OneLoop loop;
        loop.run(vec);


    }
};

int main() {
//    bool cur_num= true;
    Solution().run();
    return 0;
}

